package com.yangcangclub.trade.domain;

import com.google.common.collect.Maps;
import com.yangcangclub.commons.exception.ApolloException;
import com.yangcangclub.commons.result.MessageEnum;
import com.yangcangclub.trade.base.TradeBaseDomain;
import com.yangcangclub.trade.bean.TradeAddress;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by user on 2017/2/27.
 */
@Component
public class TradeAddressDomain extends TradeBaseDomain {

    public int insertTradeAddress(TradeAddress tradeAddress){
        super.getMasterJdbc().insert("trade.TradeAddressMapper.insertTradeAddress",tradeAddress);

        int id = tradeAddress.getId();
        if(id == 0){
            //回滚
            throw new ApolloException(MessageEnum.TRADE_ADDRESS_ADD_FAILURE);
        }
        return id;
    }

    public List<TradeAddress> selectTradeAddressByTradeNo(String tradeNo){
        Map m = Maps.newHashMap();
        m.put("tradeNo",tradeNo);
        List<TradeAddress> tradeAddressList = super.getSlaveJdbc().selectList("trade.TradeAddressMapper.selectTradeAddressByTradeNo",m);
        return tradeAddressList;
    }
}
